package leeon.kaixin.wap.models;

import java.util.ArrayList;
import java.util.List;

import leeon.mobile.BBSBrowser.utils.HTMLUtil;

public class StatusRepaste extends Status {

	private static final long serialVersionUID = -9080980899279481139L;
	
	private int newRepasteCount;
	
	private List<Repaste> newRepasteList = new ArrayList<Repaste>();

	public int getNewRepasteCount() {
		return newRepasteCount;
	}

	public void setNewRepasteCount(int newRepasteCount) {
		this.newRepasteCount = newRepasteCount;
	}

	public List<Repaste> getNewRepasteList() {
		return newRepasteList;
	}

	public void setNewRepasteList(List<Repaste> newRepasteList) {
		this.newRepasteList = newRepasteList;
	}

	@Override
	public StatusType getType() {
		return StatusType.转帖;
	}

	@Override
	protected void parseContentHtml(String htmlDiv) {
		super.parseContentHtml(htmlDiv);
		//<a href="/repaste/detail.php?uid=1858140&amp;urpid=4494477459&amp;verify=2538938_2538938_1300780186_63e34c2c3f0415708ba3686d88d0c676_kx&amp;
		//url=%2Fhome%2Fnews.php%3Fuid%3D2538938%26verify%3D2538938_2538938_1300779905_3029b0a25002d5e2bae7625f22f326cb_kx">果然是字如其人。。。</a>		
		String[] details = HTMLUtil.findStrs(htmlDiv, "<a href=\"/repaste/detail.php?", "</a>");
		for (String d : details) {
			Repaste r = new Repaste();
			r.setUid(super.getUid());
			r.setUrpid(HTMLUtil.findStr(d, "urpid=", "&amp;"));
			r.setTitle(HTMLUtil.findStr(d, "\">", "</a>"));
			r.setDate(super.getDate());
			newRepasteList.add(r);
		}
		
		//<span class="r"><a href="/repaste/index.php?uid=1858140&amp;verify=2538938_2538938_1300780229_5718888b3b232b542fa66636dfb731fe_kx&amp;
		//url=%2Fhome%2Fnews.php%3Fuid%3D2538938%26verify%3D2538938_2538938_1300779905_3029b0a25002d5e2bae7625f22f326cb_kx">21条新转帖>></a></span>
		String c = HTMLUtil.findStr(htmlDiv, "<span class=\"r\">", "条新转帖>>");
		c = HTMLUtil.removeHtmlTag(c);
		try {
			newRepasteCount = Integer.parseInt(c);
		} catch (NumberFormatException e) {
			newRepasteCount = details.length;
		}
	}
}
